#include "aclnn_spence.h"
#include "utils.h"
extern "C"
{
    int run(void *env_ptr, void *x, void *y)
    {
        uint64_t workspaceSize;
        aclOpExecutor *executor;
        // 调用aclnnAdd第一段接口
        auto ret = aclnnSpenceGetWorkspaceSize(CAST_TO_ACL_TENSOR(x), CAST_TO_ACL_TENSOR(y), &workspaceSize, &executor);
        CHECK_SUCCESS_RETURN(ret, "aclnnMseLossGradGetWorkspaceSize failed.");
        // 根据第一段接口计算出的workspaceSize申请device内存
        ALLOC_WORKSPACE(workspaceSize);
        std::cout << "workspace size = " << workspaceSize << std::endl;
        // 调用aclnnAddCustom第二段接口
        ret = aclnnSpence(workspaceAddr, workspaceSize, executor, GET_STREAM(env_ptr));
        CHECK_SUCCESS_RETURN(ret, "aclnnMseLossGrad failed.")
        return ACL_SUCCESS;
    }
}